//
//  BookPlaceDetailOneCell.m
//  FreeTrip
//
//  Created by 352324497@qq.com on 15/11/26.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "BookPlaceDetailOneCell.h"

@implementation BookPlaceDetailOneCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        CGFloat height = KScreenWidth / 630 * 330;
        self.backgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        [self.contentView addSubview:_backgroundImageView];
        
        self.titlelabel = [[UILabel alloc]initWithFrame:CGRectMake(20 * KScreenWidth / 375, height - 60 * KScreenWidth / 375, (KScreenWidth - 40 * KScreenWidth / 375), 50 * KScreenWidth / 375)];
        self.titlelabel.font = [UIFont boldSystemFontOfSize:20 * KScreenWidth / 375];
        self.titlelabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_titlelabel];
        
        CGFloat width = (KScreenWidth - 20 * KScreenWidth / 375) / 3;
        self.photosButton = [ShopButton buttonWithType:(UIButtonTypeCustom)];
        self.photosButton.frame = CGRectMake(10 * KScreenWidth / 375, height + 10 * KScreenWidth / 375, width, width);
        self.photosButton.customImageView.image = [UIImage imageNamed:@"photos"];
        [self.contentView addSubview:_photosButton];
        
        self.travelsButton = [ShopButton buttonWithType:(UIButtonTypeCustom)];
        self.travelsButton.frame = CGRectMake(10 * KScreenWidth / 375 + width, height + 10 * KScreenWidth / 375, width, width);
        self.travelsButton.customImageView.image = [UIImage imageNamed:@"travels"];
        [self.contentView addSubview:_travelsButton];
        
        self.mapButton = [ShopButton buttonWithType:(UIButtonTypeCustom)];
        self.mapButton.frame = CGRectMake(10 + KScreenWidth / 375 + width * 2, height + 10 * KScreenWidth / 375, width, width);
        self.mapButton.textLabel.text = @"地图";
        self.mapButton.customImageView.image = [UIImage imageNamed:@"map2"];
        [self.contentView addSubview:_mapButton];
        
        self.detailLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * KScreenWidth / 375,  height + width - 30 * KScreenWidth / 375, KScreenWidth - 20 * KScreenWidth / 375, 0)];
        self.detailLabel.font = [UIFont systemFontOfSize:16 * KScreenWidth / 375];
        self.detailLabel.numberOfLines = 0;
        [self.contentView addSubview:_detailLabel];
        
    }
    return self;
}

-(void)setModel:(BookPlaceDetailModel *)model
{
    CGFloat height = KScreenWidth / 630 * 330;
    CGFloat width = (KScreenWidth - 20 * KScreenWidth / 375) / 3;
    _model = model;
    
    [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.photosButton.textLabel.text = [NSString stringWithFormat:@"图片%ld", (long)model.photos_count];
    self.travelsButton.textLabel.text = [NSString stringWithFormat:@"游记%ld", (long)model.attraction_trips_count];
    self.titlelabel.text = model.name_zh_cn;
    self.detailLabel.text = model.myDescription;
    CGRect bounds = [self.detailLabel.text boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 100 * KScreenWidth / 375) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    self.detailLabel.frame = CGRectMake(10 * KScreenWidth / 375, height + width - 40 * KScreenWidth / 375, KScreenWidth - 20 * KScreenWidth / 375, bounds.size.height);
}
+(CGFloat)heightForCell:(BookPlaceDetailModel *)model
{
    CGFloat height = KScreenWidth / 630 * 330;
    CGFloat width = (KScreenWidth - 20 * KScreenWidth / 375) / 3;
    if (model.myDescription != nil)
    {
        CGRect bounds = [model.myDescription boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 100 * KScreenWidth / 375) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
        return height + width + bounds.size.height - 30 * KScreenWidth / 375;
    }
   
    return height + width + 10 * KScreenWidth / 375;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
